package test;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

    public static void main(String[] args)  {
        int port = 8080;

        try(
                ServerSocket serverSocket = new ServerSocket(port);
                Socket socket = serverSocket.accept();
                InputStream inputStream = socket.getInputStream();
                OutputStream outputStream = socket.getOutputStream();
                FileOutputStream fileOutputStream = new FileOutputStream("demo24\\src\\test\\product_server.obj");
        ) {

            byte[] buffer = new byte[1024];
            int len;
            while ((len = inputStream.read(buffer)) != -1) {
                fileOutputStream.write(buffer, 0, len);
            }

            outputStream.write("上传成功".getBytes());

        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }


}
